package com.shengyijie.activity.tab;
  

import com.shengyijie.activity.R;     
import com.shengyijie.activity.commen.SearchProActivity;
import com.shengyijie.context.ContextApplication; 
import android.app.Activity; 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener; 
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class MoreActivity extends Activity implements OnClickListener{ 
	 
	private RelativeLayout contact;
	 private RelativeLayout help; 
	 private RelativeLayout about;
	 
	 private Spinner sp_industyr;
	 private Spinner sp_city;
	 private EditText et_kw;
	 private Button search;
	 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.more); 
         initView();
         initSpinner();
    }
    
    public void initView(){
    	 contact=(RelativeLayout) this.findViewById(R.id.contact);
		 help=(RelativeLayout) this.findViewById(R.id.help); 
		 about=(RelativeLayout) this.findViewById(R.id.about); 
		 et_kw=(EditText) this.findViewById(R.id.keywords); 
		 search=(Button) this.findViewById(R.id.search); 
		 
		 contact.setOnClickListener(this);
		 help.setOnClickListener(this); 
		 about.setOnClickListener(this); 
		 search.setOnClickListener(this);
		 
		 sp_industyr=(Spinner) this.findViewById(R.id.property1);
		 sp_city=(Spinner) this.findViewById(R.id.property2);
	    	 
	 }
     
    public void initSpinner(){
   	 String[] citys={"所有区域","华北地区","东北地区","华东地区","中南地区","西南地区","西北地区"};
   	 String[] industrys={"所有行业","服饰箱包","美容保健","美酒饮料","家居环保","餐饮娱乐","教育培训","新锐创意"};
  
   	 ArrayAdapter<String> adapter1=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, industrys);  
   	 ArrayAdapter<String> adapter2=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, citys);  
   	 
   	 adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   	 adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   	 
   	sp_industyr.setAdapter(adapter1);    
   	sp_city.setAdapter(adapter2);   
   	 
   	sp_industyr.setPrompt( " 请选择主营行业 ： " );
   	sp_city.setPrompt( " 请选择投资区域 ： " ); 
   	 
   	sp_industyr.setOnItemSelectedListener(new OnItemSelectedListener() {
	            public void onItemSelected(AdapterView<?> parent,
	                View view,int position,long id) { 
	            	     ContextApplication.industry_id=position; 
	                }
	            public void onNothingSelected(AdapterView<?> parent) {
	            }
	                
	        });
   	 
   	sp_city.setOnItemSelectedListener(new OnItemSelectedListener() {
	            public void onItemSelected(AdapterView<?> parent,
	                View view,int position,long id) { 
	            	ContextApplication.city_id=position; 
	                }
	            public void onNothingSelected(AdapterView<?> parent) {
	            }
	                
	        });
   }
    
    
	@Override
	public void onClick(View v) {
		
		switch(v.getId()){
		    case R.id.contact:
		    	toActivity(AboutActivity.Page_Contact); 
		    	break;
		    case R.id.help:
		    	toActivity(AboutActivity.Page_Help); 
		    	break; 
		    case R.id.about:
		    	toActivity(AboutActivity.Page_About); 
		    	break;
		    case R.id.search:
		    	ContextApplication.keyword= et_kw.getText().toString().trim();
		    	if(ContextApplication.keyword.equals("")){
		    		Toast.makeText(this, "请输入您要搜索的内容", Toast.LENGTH_SHORT).show();
		    		et_kw.requestFocus();
		    	}else{
		    		Intent i=new Intent();
		    		i.setClass(this, SearchProActivity.class);
		    		this.startActivityForResult(i, 1);
		    	}
		    	break;
		}
		
	}
	
	public void toActivity(int type){
   	 try{
   		    AboutActivity.Page_Type=type;
            Intent it = new Intent(); 
            it.setClass(this, AboutActivity.class);
	        startActivity(it);
   	 }catch(Exception e){}
    }
    
	
	public boolean onKeyDown(int keyCode,KeyEvent event) {   
	    if (keyCode == KeyEvent.KEYCODE_BACK) { 
	    	
				 new AlertDialog.Builder(this).setTitle("提示")
				 .setMessage("确定退出？")
				 .setPositiveButton("确定", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) { 
						android.os.Process.killProcess(android.os.Process.myPid());
					}
				  })
				  .setNegativeButton("取消", new DialogInterface.OnClickListener() {
					    public void onClick(DialogInterface dialog, int whichButton) {
					     }
				  })
				  .show(); 
	         return true;   
	     }else
	         return super.onKeyDown(keyCode,event);   
	 }
    
}